package com.veetao.api.utils;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumberUtil {

	private static Random random = new Random();
	public static int randomInt(int maxExclusive) {
		return random.nextInt(maxExclusive);
	}
	
	public static int randomInt(int minInclusive, int maxExclusive) {
		return minInclusive + random.nextInt(maxExclusive - minInclusive);
	}
	public static boolean isNumber(String str) {
		if(str == null) {
			return false;
		}
		return str.matches("\\d+");
	}

	private static final Pattern p = Pattern.compile("^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9]))\\d{8}$");

	public static boolean isNotMobile(String mobile) {
		return !isMobile(mobile);
	}
	
	public static boolean isMobile(String mobile) {
		Matcher m = p.matcher(mobile);  
		return m.matches();  
	}
	/**
	 * @param content
	 * @return
	 * @author guohongtao
	 */
	public static String hideMobileNumberContent(String content) {
		if(content == null) {
			return null;
		}
//		content = content.replaceAll("\\D","");
		return content.replaceAll("((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(16[0-9])|(18[0-9]))\\d{4}(\\d{4})","$1****$7");
	}
	
	
	public static void main(String[] args) {
		String s = "15811502605";
		System.out.println(hideMobileNumberContent(s));
		s = "15811502605拉到過垃圾掛機啦李經理";
		System.out.println(hideMobileNumberContent(s));
		s = "aaaaaaaa大大嘎達個17955668899搭噶郭德綱";
		System.out.println(hideMobileNumberContent(s));
		s = "aaaaaaaa大大嘎達個17955668899搭噶郭德綱15811502605";
		System.out.println(hideMobileNumberContent(s));
		System.out.println(randomInt(10000,100000));
	}

	public static float parseFloat(String floatStr, float defaultValue) {
		try{
			return Float.parseFloat(floatStr);
		} catch(Exception e){
			
		}
		return defaultValue;
	}
}
